#ifndef _ELEMENT_HH_
#define _ELEMENT_HH_

#include <stdlib.h>
#include <time.h>

#include <vector>
#include "boost/smart_ptr.hpp"

#include "cxcore.h"

#include "PDModel.hh"
#include "PatchCluster.hh"

const unsigned int ELEMENT_MAX_PATCHES=100;
const unsigned int ELEMENT_MAX_CLUSTERS=10;


class Shape{

public:

    Shape(){centre = cvPoint(-1,-1); m_depth = -1; coeff = NULL;}

    int load(const char *filename);

    PDModel model;
    CvMat *coeff;

    CvPoint centre;

    int m_depth;

    ~Shape(){cvReleaseMat(&coeff);}
};



class Element{

public:

    Element(){m_max_patches = ELEMENT_MAX_PATCHES; m_max_clusters = ELEMENT_MAX_CLUSTERS;}

    std::vector<boost::shared_ptr<IplImage> > patches;

    std::vector<PatchCluster> clusters;
    CvPoint position;
    std::vector<double> cluster_weight;
    
    unsigned int m_max_patches;
    unsigned int m_max_clusters;
    
    int add_patch(boost::shared_ptr<IplImage> patch);

    ~Element();

private:
    
};

class SMATModel{

public:
    SMATModel();

    std::vector<Element> elements;

    Shape shape;

    std::vector<SMATModel> submodels;
    //the index of the element that is the parent of the submodel.
    std::vector<unsigned int> submod_parent;

};

#endif
